import 'package:animal/constant/color.dart';
import 'package:animal/constant/font.dart';
import 'package:animal/item/shop_cart_item.dart';
import 'package:animal/ui/shop_car/controller/shop_car_controller.dart';
import 'package:animal/utils/screen_util.dart';
import 'package:animal/widgets/appbar_widget.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';

///购物车
class ShopCarPage extends StatelessWidget {
  ShopCarPage({Key? key}) : super(key: key);
  final ShopCarController controller = Get.put(ShopCarController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: KColorConstant.appBgColor,
      appBar: AppBarWidget.defaultAppBar(
        backgroundColor: Colors.white,
        title: const Text("购物车"),
        automaticallyImplyLeading: false,
        centerTitle: true,
        elevation: 0,
        actions: [GFButton(onPressed: () {}, text: "编辑", textStyle: KFontConstant.myTextStyle(size: 16), type: GFButtonType.transparent)],
      ),
      body: Stack(
        children: [
          ListView.builder(
              itemCount: 1,
              padding: EdgeInsets.only(top: ScreenUtil().L(7.5), left: ScreenUtil().L(20), right: ScreenUtil().L(20), bottom: ScreenUtil().L(60)),
              shrinkWrap: true,
              itemBuilder: (context, index) {
                return contentWidget(onChanged: (val) => controller.selectCheck({"id": index, "data": [1, 2]}), index: index);
              }),
          Column(
            mainAxisAlignment: MainAxisAlignment.end,
            children: [
              Container(
                padding: EdgeInsets.symmetric(horizontal: ScreenUtil().L(25)),
                color: Colors.white,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        Container(
                            margin: EdgeInsets.only(right: ScreenUtil().L(10)),
                            child: Text("商品价格", style: KFontConstant.myTextStyle(size: 13, color: KColorConstant.black999999))),
                        Text("合计：", style: KFontConstant.myTextStyle(size: 15)),
                        Text("¥6049.02", style: KFontConstant.myTextStyle(size: 17, color: const Color(0XFFFF605F), bold: true)),
                      ],
                    ),
                    GFButton(
                      onPressed: () {},
                      text: "结算",
                      textStyle: KFontConstant.myTextStyle(size: 16, color: Colors.white),
                      shape: GFButtonShape.pills,
                      color: const Color(0XFFFFA940),
                    )
                  ],
                ),
              ),
            ],
          )
        ],
      ),
    );
  }

  contentWidget({void Function(bool)? onChanged, required int index}) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: ScreenUtil().L(10), horizontal: ScreenUtil().L(10)),
      margin: EdgeInsets.symmetric(vertical: ScreenUtil().L(7.5)),
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(ScreenUtil().L(10))),
      child: Column(
        children: [
          Container(
            child: Row(
              children: [
                Obx(() {
                  return GFCheckbox(
                    onChanged: onChanged,
                    value: controller.data.map((element) => element["id"]).toList().contains(index),
                    type: GFCheckboxType.circle,
                    size: ScreenUtil().L(20),
                    inactiveBorderColor: KColorConstant.black999999,
                    inactiveBgColor: Colors.white,
                  );
                }),
                Container(
                  width: ScreenUtil().L(10),
                ),
                Text("小渔具旗舰店", style: KFontConstant.myTextStyle(size: 14, bold: true)),
                const Icon(Icons.chevron_right)
              ],
            ),
          ),
          ListView.builder(
              itemCount: 1,
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              itemBuilder: (context, index) {
                return ShopCartItem(controller: controller.controller);
              })
        ],
      ),
    );
  }
}
